package com.ks.controller;

import com.ks.common.PageResult;
import com.ks.common.Result;
import com.ks.dto.PageQueryDTO;
import com.ks.service.WarnRecordService;
import com.ks.vo.RequestVO;
import com.ks.vo.ResponseVO;
import com.ks.vo.WarnRecordVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
@Slf4j
public class WarnRecordController {

    @Autowired
    private WarnRecordService warnRecordService;

    @PostMapping("/warnRecord/list")
    public Result<PageResult> list(@RequestBody PageQueryDTO pageQueryDTO) {
//        log.info("分页查询告警记录：{}", pageQueryDTO);
        PageResult pageResult = warnRecordService.pageWarnRecord(pageQueryDTO);
        return Result.success(pageResult);
    }

    @PutMapping("/warnRecord/{id}/read")
    public Result  read(@PathVariable("id") Long id) {
        log.info("已读告警记录：{}", id);
        warnRecordService.readWarnRecord(id);
        return Result.success();
    }

    //根据时间范围查找告警信息
    @PostMapping("/alert/query")
    public ResponseVO queryAlertByTime(@RequestBody RequestVO requestVO) {
        log.info("查询告警信息：{}", requestVO);
        List<WarnRecordVO> warnRecordVOList = warnRecordService.queryAlertByTime(requestVO);
        return ResponseVO.success(warnRecordVOList,requestVO,warnRecordVOList.size());
    }
}
